package cn.xenosp.server.config;

import cn.xenosp.server.common.Constant;
import cn.xenosp.server.common.SystemConfig;
import cn.xenosp.server.common.cache.Cache;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.stereotype.Component;

/**
 * 项目名： service-web
 * 包路径： cn.xenosp.server.config
 * 作者：   TongHui
 * 创建时间: 2024-08-02 14:47
 * 描述: TODO
 * 版本: 1.0
 */
@Component
public class ServerBeanPostProcessor implements BeanPostProcessor {

    @Autowired
    Cache redisCache;
    @Value("${server.servlet.context-path}")
    String basePath;

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof SystemConfig ) {
            SystemConfig bean2 = ((SystemConfig) bean);
            bean2.setBasePath(basePath);
            redisCache.set(Constant.SYSTEM_CONFIG,bean2);
            return bean2;
        }
        return bean;
    }
}
